<template>
  <div class="bg mylessons">
    <div class="lessons bgw">
      <div class="lesson_item clear animated" transition="fade" v-for="item in list">
        <a v-link="{name: 'lesson',query: {id: item.id}}">
          <div class="imgWrap">
            <img :src="item.imgs[0]" />
          </div>
        </a>
        <div class="lesson_info">
          <a v-link="{name: 'lesson',query: {id: item.id}}">
            <p class="title">
              {{item.title}}
            </p>
            <p class="desc">
              <i class="icon_1"></i>{{item.address}}
            </p>
            <p class="desc">
              <i class="icon_2"></i>{{item.time}}
            </p>
            <p class="desc">
              <i class="icon_5"></i>老师:{{item.teacher}}
            </p>
          </a>
        </div>
      </div>
    </div>
    <div class="loadingMsg" v-if="isloading">
      加载中...
    </div>
    <p class="bottom-line" v-if="!isloading&&!ismore"><span>{{list.length>0 ? '已经到底了' : '当前没有数据'}}</span></p>
    <div class="loading" v-if="!isloading&&list.length>0&&ismore" @click="nextPage()">
      点击加载更多
    </div>
  </div>
</template>
<script type="text/babel">
  import {getMyFav, yuyue} from '../factory/fav';
  export default {
    name: 'myfav',
    components: {
    },
    data () {
      return {
        list: [],
        pageIndex: 1,
        isloading: true,
        ismore: false
      };
    },
    created () {
      this.$dispatch('alert.close');
      let that = this;
      that.nextPage();
    },
    methods: {
      cancelYuyue () {
        yuyue().then(res => {
          if (!res.iserror) {
            this.$dispatch('alert', '操作成功~');
          }
        });
      },
      nextPage () {
        let that = this;
        let postParams = {page: this.pageIndex++, size: 5};
        that.isloading = true;
        getMyFav(postParams).then(function (res) {
          if (!res.iserror) {
            that.list = that.list.concat(res.data.list);
            that.ismore = true;
            if (res.data.count <= that.list.length) {
              that.ismore = false;
            }
          }
          that.isloading = false;
        });
      }
    }
  };
</script>
